<template>
  <div class="login_container">
    <div class="login_box_container">
      <div class="login_box_header_container">UNI-ADMIN</div>
      <div class="login_form_container">
        <div class="login_form_input_container">
          <el-form :model="formData">
          <el-form-item>
            <el-input v-model="formData.userName"
            placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="formData.password"
            placeholder="请输入密码"></el-input>
          </el-form-item>
        </el-form>
        </div>
        <button @click="onClick">立即登录</button>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data(){
    return{
      formData:{
        userName:"",
        password:""
      }
    }
  },
  methods:{
    onClick(){
      axios.post("http://ceshi5.dishait.cn/admin/login",{
        username:this.formData.userName,
        password:this.formData.password
      }).then((res)=>{
        console.log(res);
        var token = res.data.data.token;
        window.localStorage.setItem("token",token)
        this.$router.push("/")
      }).catch((error)=>{
        this.$message.error('登录失败');
        console.log(error)
      })
    }
  }
}
</script>


<style scoped>
.login_container
{
  width: 100vw;
  height: 100vh;
  display: inline-flex;
  justify-content: center;
  /* align-items: center; */
}

.login_box_container
{
  width: 40vw;
  height:42vh;
  border: 1px solid gainsboro;
  margin-top: 10vh;
}

.login_box_header_container
{
  width: 100%;
  height: 10vh;
  border-bottom: 1px solid gainsboro;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  color: black;
  font-size: 30px;
  font-weight: 600;
}

.login_form_container
{
  width: 100%;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.login_form_input_container
{
  width: 80%;
}
</style>